package handler

import (
	"github.com/gin-gonic/gin"
	"read-pic-sys/model"
)

func Add(c *gin.Context) {
	name := c.PostForm("name")
	comment := c.PostForm("comment")
	author := c.PostForm("author")

	data := model.ImgWord{
		Name:    name,
		Comment: comment,
		Author:  author,
	}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	} else {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "添加成功",
		})
		return
	}
}

func List(c *gin.Context) {
	var word []model.ImgWord
	model.DB.Debug().Find(&word)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  word,
	})
}
